package com.zykj.command;

/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Title: RemoteControl
 * @Project: ${MODEL_NAME}
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 53
 * @since 2018/12/31-23:53
 */
public class RemoteControlWithUndo {
    Command[] onCommands;
    Command[] offCommands;
    Command undoCommand;

    public RemoteControlWithUndo() {
        onCommands = new Command[7];
        offCommands = new Command[7];

        NoCommand noCommand = new NoCommand();
        for (int i = 0; i < 7; i++) {
            onCommands[i] = noCommand;
            offCommands[i] = noCommand;
        }
    }

    public void setCommand(int slot, Command onCommand, Command offCommand) {
        if(onCommand!=null)
        this.onCommands[slot] = onCommand;

        if(offCommand!=null)
        this.offCommands[slot] = offCommand;
    }

    public void offButtonPress(int slot) {
        this.offCommands[slot].execute();
        undoCommand = this.offCommands[slot];
    }
    public void onButtonPress(int slot) {
        this.onCommands[slot].execute();
        undoCommand = this.offCommands[slot];
    }

    public void undoButtonPress(int slot) {
        undoCommand.undo();
    }

}
